<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    用户名: <input type="text" id="userName" >
    <br>
    <input type="button" id="btn" value="注册">
    <br>
    <button id="clear">清除</button>
</body>
<script>
    
    var userName = document.getElementById('userName');
    var btn = document.getElementById('btn');
    var clear = document.getElementById('clear');
    btn.onclick = function(){
        // console.log('我是可以的')
        if(userName.value.length < 6 || userName.value.length > 12){
            alert('输入不正确')
        }
    }
    clear.onclick = function(){
        userName.value = '';
    }

</script>
</html>